<?php
/**
 * 文件名：xwb.mod.php
 * 版本号：1.0
 * 最后修改时间：2010年12月6日 17:15:24
 * 作者：狐狸<foxis@qq.com>
 * 功能描述: 新浪微博接口模块
 */


if(!defined('IN_JISHIGOU'))
{
    exit('invalid request');
}

class ModuleObject extends MasterObject
{

	function ModuleObject($config)
	{
		$this->MasterObject($config);
        
                
        set_time_limit(300);
        

		if ($this->Config['sina_enable'] && sina_weibo_init($this->Config))
		{
			;
		}
		else
		{
			$this->Messager("整合新浪微博的功能未开启",null);
		}

		$this->Execute();
	}

	
	function Execute(){      
		ob_start();
		switch ($this->Code)
        {
			case 'enter':
				$this->Enter();
				break;

            case 'synctopic':
                require_once ROOT_PATH.'private/classes/sina.inc.php';
                $sinainc = new sinainc($this);   	
            	$sinainc->SyncTopic();
                break;             

			default:
				$this->Main();
		}

		exit;
	}


	function Main(){
		require_once ROOT_PATH . 'include/xwb/sina.php';
        XWB_plugin::init();
		XWB_plugin::request();
	}


    
	function Enter()
	{
	    $share_time = $this->Request['share_time'];
		if (MEMBER_ID > 0 && $share_time>0 && ($share_time + 300 > time()))
		{
			$bind_info = sina_weibo_bind_info(MEMBER_ID);

            if($share_time==$bind_info['share_time'])
            {
                $_site_url = substr($this->Config['site_url'],strpos($this->Config['site_url'],':/'.'/') + 3);

                $share_msg = "我刚绑定了新浪微博帐户，可以使用新浪微博帐户登录{$this->Config['site_name']}(".$_site_url.")、不再担心忘记密码；还可以在{$this->Config['site_name']}发微博同步发到新浪上，吸引更多人关注；你也来试试吧 ".get_full_url($this->Config['site_url'],"index.php?mod=tools&code=sina")." ";

                Load::logic('topic');
                $TopicLogic = new TopicLogic($this);

                
                $_POST['syn_to_sina'] = (sina_weibo_bind_setting($bind_info) ? 1 : 0);
                $add_result = $TopicLogic->Add($share_msg);

                
                $this->DatabaseHandler->Query("update ".TABLE_PREFIX."xwb_bind_info set `share_time`='".mt_rand(1,1111111111)."' where `uid`='".MEMBER_ID."'");
            }
		}

        exit;
	}
   
   

}

?>